﻿@model Sharp.Web.Models.OrgForBusinesModel

@using Ext.Net
@using Ext.Net.MVC

<script>
    function submitReadyData() {
        var button = Ext.getCmp("prevButton");
        var form = button.up("form").getForm();
        var window = button.up("window");
        var fields = form.getFields();
        for (var i = 0; i < fields.getCount() ; i++) {
            var field = fields.getAt(i);
            if (field.getId() === "OrgIds") {
                var tree = window.down("#selectedTree").down("treeview");
                field.setValue(tree.dataSource.data.keys.join(','));
            }
            if (field.getId() === "PersonIds") {
                var data = button.up("window").down("#employeeGridSelected").getStore().data;
                var personIds = new Array();
                for (var y = 0; y < data.items.length; y++) {
                    personIds.push(data.items[y].getData().Id);
                }
                field.setValue(personIds.join(','));
            }
        }
    }
</script>
@{
    var x = Html.X();
    var employeeGrid = new GridPanel()
    {
        ItemID = "employeeGrid",
        Title = "业务组织结构所有人",
        Width = 500,
        Height = 300,
        Region = Region.West,
        MultiSelect = true,
        ColumnModel =
        {
            Columns =
            {
                x.Column().DataIndex("Id").Hidden(true),
                x.Column().DataIndex("FullName").Text("姓名").Width(150)
            }
        }
        ,
        Store ={ x.Store().Model(x.Model().Fields("FullName"))
                .Proxy(x.AjaxProxy().Url(Url.Action("GetEmployees","Employe"))
                .Reader(x.JsonReader().RootProperty("data")))
                .RemoteSort(true)
                .Sorters("Id", Ext.Net.SortDirection.DESC).AutoLoad(false)
         },
        View =
        {
            x.GridView().Plugins(x.GridDragDrop())
        }
    };
    var employeeGridSelected = new GridPanel()
    {
        ItemID = "employeeGridSelected",
        Title = "选用的参与者",
        Width = 500,
        Height = 300,
        Region = Region.Center,
        MultiSelect = true,
        ColumnModel =
        {
            Columns =
            {
                x.Column().DataIndex("Id").Hidden(true),
                x.Column().DataIndex("FullName")
            }
        },
        View =
        {
            x.GridView().Plugins(x.GridDragDrop())
        }
    };
}
 
@(
 x.Window().Layout(LayoutType.Fit).Title("添加")
            .CloseAction(CloseAction.Destroy)
                .Width(900).Height(600)
            .Items(
                x.FormPanel().Layout(LayoutType.Card).Border(false).ActiveIndex(0).Items(
                                    x.FormPanel().ItemID("LA").Default().Title("第一步：基本").Border(false).Items(
                                    
                                    x.TextFieldFor(f => f.Title).Width(480), 
                                    x.TextAreaFor(f => f.Remark).Width(480),
                                    x.HiddenFor(f => f.ParentId),
                                            x.HiddenFor(f => f.OrgIds),
                                            x.HiddenFor(f => f.PersonIds)
                                    
                                    ).BodyStyle("overflow-x:hidden; overflow-y:auto"),
                                x.FormPanel().ItemID("LB").Border(false).Title("第二步：配置业务组织结构").Layout(LayoutType.Border).Items(
                                    x.TreePanel().Region(Region.West).Width(420).Root(Model.OrgTree).RootVisible(false).View(x.TreeView().Plugins(x.TreeViewDragDrop().AllowLeafDrop(true).DDGroup("BuildNewTree"))),
                                        x.TreePanel().ItemID("selectedTree").Region(Region.Center).Root(
                                            new Node()
                                                {
                                                    Text = "业务组织结构",
                                                    NodeID = Guid.Empty.ToString(),
                                                    Expanded = true,
                                                    AutoDataBind = false,
                                                    Checked = null,
                                                    EmptyChildren = true
                                                }
                                        ).Mode(TreePanelMode.Local).View(x.TreeView().Plugins(x.TreeViewDragDrop().AllowLeafDrop(true).DDGroup("BuildNewTree")))),
                                        x.FormPanel().ItemID("LC").Layout(LayoutType.Border).Border(true).Title("参与人员").Items(employeeGrid, employeeGridSelected)
                ).FooterBar(
                                        x.Toolbar().Items(
                                                x.Button().ID("prevButton").Text("« 上一步").Handler("function(btn) {navigate(btn.up(\"panel\"), \"prev\"); }").Disabled(true),
                                            x.ToolbarFill(),
                                                    x.Button().ID("nextButton").Text("下一步 »").Handler("function(btn) {navigate(btn.up(\"panel\"), \"next\"); }"),
                                                    x.ToolbarFill(), x.Button().Text("完成").OnClientClick("submitReadyData").DirectEvents(de =>
                                {
                                    de.Click.Action = "Save";
                                    de.Click.EventMask.ShowMask = true;
                                    de.Click.EventMask.Msg = "正在提交...";
                                    de.Click.EventMask.MinDelay = 1000;
                                    de.Click.Success = "App.Edit.PostBackSuccess";
                                }))
                    )

            )
)
